//
//  AccountTicketDetailVC.m
//  ImGuider
//
//  Created by 王鹏宇 on 2017/12/7.
//  Copyright © 2017年 AudioCtrip. All rights reserved.
//

#import "AccountTicketDetailVC.h"
#import "TicketDetailCell.h"
@interface AccountTicketDetailVC ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>

@property (nonatomic, strong) UICollectionView * collectionView;

@property (nonatomic, strong) UIPageControl * pageControl;

@end

@implementation AccountTicketDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setup];
}



- (void)setup {
    
    self.barBGAlpha = 0.f;
    self.customBarStyle = UIStatusBarStyleLightContent;
    self.title = MYLocalizedString(@"TICKET_E_TICKET", nil);
    self.view.backgroundColor = [UIColor whiteColor];
    
    UIView *bgView = [[UIView alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:bgView];
    bgView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.7];
    
    UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc] init];
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    layout.minimumLineSpacing = 0.f;
    layout.itemSize = CGSizeMake(kScreenWidth,(kScreenWidth - 72)/15*17 + 180);
    //创建Collection
    _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0,kNavigationBarHeight, kScreenWidth, kScreenHeight - kNavigationBarHeight - 65) collectionViewLayout:layout];
    _collectionView.pagingEnabled = YES;
    _collectionView.dataSource = self;
    _collectionView.backgroundColor = [UIColor clearColor];
    _collectionView.delegate = self;
    _collectionView.showsVerticalScrollIndicator = NO;
    _collectionView.showsHorizontalScrollIndicator = NO;
    [_collectionView registerNib:[UINib nibWithNibName:@"TicketDetailCell" bundle:nil] forCellWithReuseIdentifier:@"TicketDetailCell"];
    [self.view addSubview:_collectionView];
    
    self.pageControl.numberOfPages = self.uploadOrderModel.tickets.count;
    self.pageControl.currentPage = 0;
}

- (UIPageControl *)pageControl {
    CGFloat bottomH = 23;
    if (ISiPhoneX) {
        bottomH = bottomH + 34;
    }
    
    if (!_pageControl) {
        _pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake((kScreenWidth - 200)/2, kScreenHeight - bottomH - 20,200,20)];
        [self.view addSubview:_pageControl];
    }
    
    return _pageControl;
}

#pragma mark  -- scrollViewDelegate

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    
    CGFloat index = scrollView.contentOffset.x/kScreenWidth;
    if (index>=0 && index < self.pageControl.numberOfPages) {
        self.pageControl.currentPage = index;
    }
}
    

#pragma mark   --UICollectionViewDelegate,UICollectionViewDataSource
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return self.uploadOrderModel.tickets.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    TicketDetailCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"TicketDetailCell" forIndexPath:indexPath];
    
    CompeleteTicketeModel * ticket = self.uploadOrderModel.tickets[indexPath.row];
    
    [cell configDataWith:ticket Pic:self.uploadOrderModel.pictureArray.firstObject Title:self.uploadOrderModel.subject Date:self.uploadOrderModel.visitdate];
    
    return cell;
}


//- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
//
//    return UIEdgeInsetsMake(0, 18, 18, 0);
//}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
